require 'cgi'

module WPSpider
  module Common

    #
    # HTTP Request class.
    #
    class HttpRequest

      #
      # Constructor.
      # - cgi
      #
      def initialize(cgi)
        @cgi = cgi
        @params = cgi.params
        @cookies = cgi.cookies
      end

      #
      # Gets request parameter.
      # - name: Paramter name.
      # - n: Order in Array params[name]
      # - returns: Parameter value.
      #
      def get_param(name, n=0)
        return @params[name] ? @params[name][n] : nil
      end

      #
      # Gets all parameters.
      # - return: Hash.
      #
      def get_params()
        return @params
      end

      #
      # Gets request cookie.
      #
      def get_cookie(name, n=0)
      return @cookies[name] ? @cookies[name][n] : nil
      end

      #
      # Gets all cookies.
      #
      def get_cookies()
        return @cookies
      end
    end
  end
end
